package com.yfjin_rtmp;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.media.projection.MediaProjection;
import android.media.projection.MediaProjectionManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


    static {
        System.loadLibrary("native-lib");
    }


    MediaProjectionManager mediaProjectionManager;
    MediaProjection mediaProjection;
    private ScreenLive screenLive;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    public void startLive(View view) {
        mediaProjectionManager= (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
        Intent intent=mediaProjectionManager.createScreenCaptureIntent();
        startActivityForResult(intent,1000);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==1000&& resultCode==Activity.RESULT_OK){
            mediaProjection=mediaProjectionManager.getMediaProjection(resultCode,data);
            screenLive=new ScreenLive();
            screenLive.startLive("rtmp://192.168.17.83:1935/live/home",mediaProjection);
        }
    }

    public void stopLive(View view) {

    }
}
